Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

349
Visualizações
MAC OS X difference between "open APP.app" and "APP.app/content/MacOs/APP" shell scripts

Somehow I get a problem, if I call an application twice or several times but only one instance should be running (which is desired).

First some (probably necessary) background information:

  • working on MAC OS X El Capitan (10.11.6)
  • I've got an Application made by node.js, electron and build by "npm build -m" (let's call it APP.app)
  • I installed the application App.app into program-folder by opening the built dmg-file and move it into the program-folder
  • Then I start the application App.app by click on the App.app-icon in program-folder
  • The application starts with a visible Window and also has an hidden background process running
  • If I close the visible Window, the App.app-Icon remains in the dock (which is okay, since the background-process is still running)
  • Now (and this is the difference to the windows build and running in windows), if I click again on the App.app-Icon in the program-folder, I only get a focus on the already running application INSTEAD of opening the window and close the old application (I can see te focus switch/activation by the switching menu name beside the apple-logo on top of the screen; it becomes "App")
  • the closing of the previous running instance is defined in electron code in the init-method as follows:

        var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
        console.info('starting new instance');
        initInternal(commandLine);
        // Someone tried to run a second instance, we should focus our window.
        var windows = options.closeWindowsOnRestart ? Browser.getAllWindows() : appWindows.slice();
        windows.forEach(function (val, index) {
            val.close();
        });
        readyCallback();
    });
    

So, I did some homework and could figure out following:

  • my App.app-icon-click should look something like open /Applications/App.app
  • with this, I get the same problem as descriped above if I call it again (it only focusses the already opened window)
  • Now comes the funny part. If I open the application by calling directly /Applications/App.app/content/MacOS/App.app the old application-instance is closed and new App.app-application is started
  • I read through open-manual and could figure out, that if I use the -n-flag, the application starts succesful a new instance, too. (open /Applications/App.app -n)

I was wondering WHY? Do you have any clues? What is the difference between open and directly call of the application?

I suggest that the info.pklist in App.app-package is making the open-call different to the direct call of App.app.

BTW: Unfortunately I already tried to add try-catch-blocks to debug the problem, but open does not give an output to terminal, it just opens the call whereas the direct call does not throw an error and everything works fine. Anyway, I believe it's more a MAC OS X problem than an App.app-problem.

Hopefully there's somebody with same problems and a solution for me

Don't hesitate to ask for more details, if needed.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Short Version:

  • open starts the application with the LaunchService (and possible added launch-parameters in info.plist)
  • whereas direct call of the application just starts the application iself without any other launch-options

*Long Version *

I read through the open manual (man open; Source: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/open.1.html) and could figure out, that "the default application as determined via LaunchServices is used to open the specified files" if you click on an item.

So I read through the LaunchService-documentation and could figure out following:

"Opening Items by File-System Reference [...] default way: If the designated item is an application: [...] If the application is already running, it is activated (brought to the front of the screen) and sent an 'rapp' (“reopen application”) Apple event."

(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCTasks/LSCTasks.html#//apple_ref/doc/uid/TP30000999-CH203-TP9)

This reflects exactly my watching that if I click on the icon the second time, the app is just focussed/activated.

Thus I need the possibility to tell the application to open a new instance (oapp-event) instead of activating the already opened application (rapp-event)

Further reading lead me to following informations:

"Launch Options When opening an application (whether by itself or to open one or more documents or URLs), you can specify various launch options to control the manner in which it is launched or activated. These can include: [...] Whether to launch a new instance of the application, even if another instance is already running"

(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html#//apple_ref/doc/uid/TP30000999-CH202-BABBJHID)

Thus I only need to add the "launch option" to define, that a new instance should be created instead of activating the existing one. But there's not written what the launch-option for it is and how they will be applied to the application (I suggest it belongs into info.plist-file).

So at least this is the answer to my original question, so I posted it here.

open - starts the application with the Launch-Service (and the defined option-parameters in info.plist) whereas direct call of the application just starts the application iself without any other launch-options

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda